<admintpl file="header" />
<style type="text/css">
	body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
</style>
</head>

<body>
<div class="" id="loading" style="width:100%;text-align: center;"><img src="__PUBLIC__/images/loading.gif" /></div>
<div id="allmap">

</div>
<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=OkM4ci06ibVrimvizgsIWv0sjASIa7BK&s=1"></script>
<script type="text/javascript">
    // 百度地图API功能
    var route = '<php> echo json_encode($route);</php>';
    route = eval("(" + route + ")");
    var map = new BMap.Map("allmap");

    map.centerAndZoom("郑州市", 11);

	 map.addEventListener("tilesloaded",function(){
    	document.getElementById("loading").style.display="none";
    });
    //map.enableScrollWheelZoom(); //启用滚轮放大缩小，默认禁用
    //map.enableContinuousZoom();
    var p1 = new BMap.Point(route.shippingLng,route.shippingLat);
    var p2 = new BMap.Point(route.collectLng,route.collectLat);

//    var driving = new BMap.DrivingRoute(map, {renderOptions:{map: map, autoViewport: true}, onPolylinesSet:function(routes) {
//        searchRoute = routes[0].getPolyline();//导航路线
//        map.addOverlay(searchRoute);
//    },
//        onMarkersSet:function(routes) {
//            map.removeOverlay(routes[0].marker); //删除起点
//            map.removeOverlay(routes[1].marker);//删除终点
//        }});
//    driving.search(p1, p2);

//    var walking = new BMap.WalkingRoute(map, {renderOptions:{map: map, autoViewport: true}, onPolylinesSet:function(routes) {
//        searchRoute = routes[0].getPolyline();//导航路线
//        map.addOverlay(searchRoute);
//    },
//        onMarkersSet:function(routes) {
//            map.removeOverlay(routes[0].marker); //删除起点
//            map.removeOverlay(routes[1].marker);//删除终点
//    }});
//    walking.search(p1, p2);

    var driving = new BMap.DrivingRoute(map, {
        renderOptions: {
            map: map,
            autoViewport: true
        },
        policy: 1,
        onMarkersSet: function (routes) {
         map.removeOverlay(routes[0].marker); //删除起点
         map.removeOverlay(routes[1].marker);//删除终点
         }
    });
    driving.search(p1, p2);

    // 添加带有定位的导航控件
    var navigationControl = new BMap.NavigationControl({
        // 靠左上角位置
        anchor: BMAP_ANCHOR_TOP_LEFT,
        // LARGE类型
        type: BMAP_NAVIGATION_CONTROL_LARGE,
        // 启用显示定位
        enableGeolocation: true
    });
    map.addControl(navigationControl);
    // 添加定位控件
    var geolocationControl = new BMap.GeolocationControl();
    geolocationControl.addEventListener("locationSuccess", function(e){
        // 定位成功事件
        var address = '';
        address += e.addressComponent.province;
        address += e.addressComponent.city;
        address += e.addressComponent.district;
        address += e.addressComponent.street;
        address += e.addressComponent.streetNumber;
        //alert("当前定位地址为：" + address);
    });
    geolocationControl.addEventListener("locationError",function(e){
        // 定位失败事件
        //alert(e.message);
    });
    map.addControl(geolocationControl);
    var styleJson = [
        {
            "featureType": "road",
            "elementType": "all",
            "stylers": {
                "lightness": 20
            }
        },
        {
            "featureType": "highway",
            "elementType": "geometry",
            "stylers": {
                "color": "#f49935"
            }
        },
        {
            "featureType": "railway",
            "elementType": "all",
            "stylers": {
                "visibility": "off"
            }
        },
        {
            "featureType": "local",
            "elementType": "labels",
            "stylers": {
                "visibility": "off"
            }
        },
        {
            "featureType": "water",
            "elementType": "all",
            "stylers": {
                "color": "#d1e5ff"
            }
        },
        {
            "featureType": "poi",
            "elementType": "labels",
            "stylers": {
                "visibility": "off"
            }
        }
    ]
    map.setMapStyle({styleJson:styleJson});

    var myIcon1 = new BMap.Icon("__PUBLIC__/images/send.png", new BMap.Size(20, 35));
    var marker3 = new BMap.Marker(p1, {icon: myIcon1});  // 创建标注
    map.addOverlay(marker3);
    var myIcon2 = new BMap.Icon("__PUBLIC__/images/get.png", new BMap.Size(20, 35));
    var marker4 = new BMap.Marker(p2, {icon: myIcon2});  // 创建标注
    map.addOverlay(marker4);

    if( 7!= route.status && 1 != route.status) {
        //pnroute();
    }
    function pnroute(){
        $.ajax({
            type: "GET",
            async: true,
            url: "{:U('pnRoute',array('order_id'=>$route['order_id']))}",
            dataType: "json",
            success: function(data) {
                var pt = new BMap.Point(data.longitude, data.latitude);
                var myIcon = new BMap.Icon("__PUBLIC__/images/pn.png", new BMap.Size(40, 40));
                var marker2 = new BMap.Marker(pt, {icon: myIcon});  // 创建标注
                map.addOverlay(marker2);
            }
        });
        setTimeout("pnroute()",3000);
    }
</script>
</body>
</html>